//
//  NewsListModel.m
//  MyAppDemo
//
//  Created by 千锋 on 15/12/5.
//  Copyright (c) 2015年 Aike. All rights reserved.
//

#import "NewsListModel.h"
#import "GDataXMLNode.h"

@implementation NewsListModel

+(NSMutableArray *)parseXMLWithData:(NSData *)data andPage:(NSInteger)page{
    GDataXMLDocument * document = [[GDataXMLDocument alloc]initWithData:data options:0 error:nil];
    NSString * newsPath = [NSString stringWithFormat:@"oschina/newslist/news"];
    NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@", dataDict);
    NSArray * newsElementArray = [document nodesForXPath:newsPath error:nil];
    NSMutableArray * newsListArray = [[NSMutableArray alloc]init];
    for (GDataXMLElement * element in newsElementArray) {
        NewsListModel * model = [[NewsListModel alloc]init];
        //读取ID
        GDataXMLNode * idNode = [element childAtIndex:0];
        model.ID = idNode.stringValue;
        GDataXMLNode * titleNode = [element childAtIndex:1];
        model.title = titleNode.stringValue;
        GDataXMLNode * bodyNode = [element childAtIndex:2];
        model.body = bodyNode.stringValue;
        GDataXMLNode * commentCountNode = [element childAtIndex:3];
        model.commentCount = commentCountNode.stringValue;
        GDataXMLNode * authorNode = [element childAtIndex:4];
        model.author = authorNode.stringValue;
        GDataXMLNode * authoridNode = [element childAtIndex:5];
        model.authorid = authoridNode.stringValue;
        GDataXMLNode * pubDateNode = [element childAtIndex:6];
        model.pubDate = pubDateNode.stringValue;
        GDataXMLNode * newstypeNode = [element childAtIndex:7];
        model.newstype = newstypeNode.stringValue;
        [newsListArray addObject:model];
        
        
    }
    return newsListArray;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}


@end
